import { defineStore } from 'pinia'
import { addRole, deleteRole, editRole, getRoleList } from '@/service/role/index.js'
import responseMessage from '@/utils/response.js'

const useRoleStore = defineStore('role', {
  state: () => ({
    roleList: '',
    totalCount: ''
  }),
  actions: {
    //查询角色信息
    async getRoleListAction(page, size, searchParams) {
      const res = await getRoleList(page, size, searchParams)
      this.roleList = res.data
      this.totalCount = res.data.total
    },
    // 添加角色信息
    async addRoleAction(addForm) {
      const res = await addRole(addForm)
      responseMessage(res)
    },
    //编辑角色信息
    async editRoleAction(addForm) {
      const res = await editRole(addForm)
      responseMessage(res)
    },
    //删除角色信息
    async deleteRoleAction(roleId) {
      const res = await deleteRole(roleId)
      responseMessage(res)
    }
  }
})

export default useRoleStore
